package com.lmt.config.shiro;

import lombok.extern.log4j.Log4j2;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Log4j2
@Component
@SuppressWarnings("unchecked")
public class ShiroRedisCacheManager implements CacheManager {

    private final RedisTemplate redisTemplate;

    @Autowired
    public ShiroRedisCacheManager(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return (Cache<K, V>) new ShiroRedisCache<>(redisTemplate);
    }

}
